#include <iostream>
#include <Windows.h>
#define FILE_DEVICE_FILE_DISK       0x8000
#define IOCTL_FILE_DISK_MOUNT   CTL_CODE(FILE_DEVICE_FILE_DISK, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
#define IOCTL_FILE_DISK_UNMOUNT  CTL_CODE(FILE_DEVICE_FILE_DISK, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

#define	SYM_LINK_DISK	"\\Device\\MYDEVICE"
#define	SYM_LINK_FUNC	L"\\DosDevices\\MyFDOLink"

int main()
{
	HANDLE h;
	DWORD junk = 0;
	int x;
	//DISK_GEOMETRY *pdg = NULL;
	h = CreateFile(__TEXT("\\\\.\\MyFDOLink"),
		GENERIC_ALL,          // open for writing
		0,                      // do not share
		NULL,                   // default security
		OPEN_EXISTING,             // create new file only
		FILE_ATTRIBUTE_NORMAL,  // normal file
		NULL);
	std::cout << h << std::endl;
	std::cin >> x;
	if (x == 1)
	{
		if (DeviceIoControl(h, IOCTL_FILE_DISK_MOUNT, NULL, 0, NULL, 0, &junk, NULL))
		{
			std::cin >> x;
			DefineDosDevice(DDD_RAW_TARGET_PATH, __TEXT("H:"), __TEXT(SYM_LINK_DISK));
		}
		else std::cout << "error";
	}
	else
	{
		//DeviceIoControl(h, IOCTL_FILE_DISK_UNMOUNT, NULL, 0, NULL, 0, &junk, NULL);
		DefineDosDevice(DDD_REMOVE_DEFINITION, __TEXT("H:"), NULL);
	}
	CloseHandle(h);
	return 0;
}